import 'package:flutter/material.dart';
import 'dart:io' show Platform;
import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:window_manager/window_manager.dart';
import 'package:provider/provider.dart';
import 'core/auth_store.dart';
import 'pages/home_page.dart';
import 'core/theme_config.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if (!kIsWeb && (Platform.isWindows || Platform.isLinux || Platform.isMacOS)) {
    await windowManager.ensureInitialized();
    const windowOptions = WindowOptions();
    await windowManager.waitUntilReadyToShow(windowOptions, () async {
      await windowManager.show();
      await windowManager.focus();
    });
  }
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => ThemeConfig()),
        ChangeNotifierProvider(create: (_) => AuthStore()..load()),
      ],
      child: Consumer<ThemeConfig>(
        builder: (context, themeConfig, child) {
          return MaterialApp(
            debugShowCheckedModeBanner: false,
            title: 'Stars Moon Player',
            theme: ThemeData(
              colorScheme: ColorScheme.fromSeed(seedColor: themeConfig.currentPrimaryColor),
              useMaterial3: true,
            ),
            home: const HomePage(),
          );
        },
      ),
    );
  }
}
// HomePage is the app entry; implementation is in pages/home_page.dart
